Ext.define('AmpleHarvest.objects.breadcrumbs.cBreadcrumbs',
{
	extend			: 'Ext.grid.Panel',
	alias			: 'widget.ampleharvest-objects-breadcrumbs-cbreadcrumbs',
	title			: 'BreadCrumbs',
	columns			: [{header: 'Name', dataIndex : 'name', flex : 1}],
//	store			: Ext.create('Ext.data.Store', {
//		fields 	: ['name'],
////		storeID	: 'myStoreIdIsCool',
//		data 	: {},
//		     	       proxy: {
//		     	          type: 'memory',
//		     	          reader: {
//		     	              type: 'json',
//		     	              root: 'items'
//		     	          }
//		     	      }
//	}),
	bubbleEvents	:
		[
			'doclassificationchange'
		],
	listeners		:
	{
		'itemclick'	:
		{
			fn	: function(record, item, index, e)
			{
				var recs = this.getSelectionModel().getSelection();
				Ext.Array.each(recs, function(obj, index, arr_all)
					{
						var obj_server = obj.get('server');
						var obj_id = obj.get('id');
//						alert(obj_server+'::'+obj_id);
						m_obj_AmpleHarvest_ViewPort.fireEvent(
								AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_ARTICLE_OPEN,
								obj_id, ''
						);
					}
				);
			}
		},
		brokerResponse	: function(obj_response)
		{
			this.add_JsonObject(obj_response.data);
			this.ahCaller.fireEvent('objectResponse', this);
			this.fireEvent(
					AmpleHarvest.layout.cLayout.C_STR_EVENT_CLASSIFICATION_CHANGE,
					obj_response.classification
			);
		}
	},
	
	

	initComponent	: function()
	{
		var obj_This = this;
		
		var util_db_breadcrumbs = Ext.create('AmpleHarvest.util.dataBroker');
		util_db_breadcrumbs.brokerData(this, this.m_str_id, 'ampleharvest-objects-breadcrumbs-cbreadcrumbs');	
		
		this.store = Ext.create('Ext.data.Store', {
			fields 	: ['name'],
//			storeID	: 'myStoreIdIsCool',
			data 	: {},
			     	       proxy: {
			     	          type: 'memory',
			     	          reader: {
			     	              type: 'json',
			     	              root: 'items'
			     	          }
			     	      }
		});
		
		this.callParent();
	},
	
	add_JsonObject	: function(JsonObject)
	{

		this.itemCount = 0;

		if(JsonObject.label)
		{
//			m_obj_AmpleHarvest_ViewPort
//			.fireEvent(
//					AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_REDIRECT,
//					obj_Link.serverId, obj_Link.id
//			);
			
			
			this.store.add(AmpleHarvest.DATA.Model.cMetadata.create(
					{
						name	: JsonObject.label,
						server	: JsonObject.serverId,
						id		: JsonObject.id	
					}));
			this.itemCount++;
		}
	},
	
	hasData			: function()
	{
		if (!this.itemCount)
		{
			return false;
		}
		if (this.itemCount < 1)
		{
			return false;
		}
		this.setTitle(this.title + ' (' + this.itemCount + ')');
		return true;
	}
}
);
